//公共
import myHeader from "/pages/headerfoot/pages/header.vue"
//公共底部
import Tabbar from "/pages/headerfoot/pages/benefitfooter.vue";
//骨架
import uniSkeleton from "/plugin/skeleton/components/heaven-skeleton/heaven-skeleton.vue";
//公共公益方法
import commonBenefit from '@/common/commonbenefit.js';
//公共方法
import Base from '@/common/base.js';
//语言
import Lang from '@/utils/lang.js';
//微信api
import weChat from '@/lib/wechat.js';
//cache缓存
import Cache from '@/utils/cache.js';
// 图标1
import uniIcons from "/uni_modules/uni-icons/components/uni-icons/uni-icons.vue";

export default {
	components: {
		uniIcons,
		Tabbar,
		myHeader,
		uniSkeleton,
	},
	data() {
		return {
			loading: true, //骨架
			toptitle: Lang.lang.usercenter, //头部
			projectuser: commonBenefit.automaticurl('projectuser'), //跳转
			studentreg: commonBenefit.automaticurl('studentreg'), //跳转
			reviewapplication: commonBenefit.automaticurl('reviewapplication'), //跳转
			mycode: commonBenefit.automaticurl('mycode'), //跳转
			mycodelist: commonBenefit.automaticurl('mycodelist'), //跳转
			
			
			trainingrecord: Lang.lang.trainingrecord, //训练记录
			datamodification: Lang.lang.datamodification, //资料修改
			reviewapplicationname: Lang.lang.reviewapplication, //审核申请
			lang: Lang.lang, //语言
			applaymanage: [], //申请信息
			ifmytream:0,//是否显示我的小队 1=开启
			activation_time:Cache.get('activation_time'),//到期时间
			activation:Cache.get('activation'),////1=永久激活
		}
	},

	onShow() {
		var that = this;
		that.ifreglogin();
		that.apply(); //审核申请
		that.loading = false; //骨架
		that.getinfo(); //获取用户信息
	 
		
	},
	onLoad() {

	},

	methods: {
		//判断是否需要注册或者登录与其他
		async ifreglogin() {
			var that = this;
			//注册
			await Base.globalauthorization();
			//判断学生是否注册
			await commonBenefit.ifStudenter().then(res => {
				if (res) {
					uni.redirectTo({
						url: commonBenefit.automaticurl('studentreg')
					})
				}
			});
		},
		getinfo() { //获取用户信息
			var that = this;
			var data={};
			 commonBenefit.getUserApiMethod(data).then(res => {
				if (res) {
					that.ifmytream=res.is_team;//是否显示我的小队
					that.activation_time=res.activation_time;
					that.activation=res.activation;
					
				}
			});
		},
		
		noticesubmit(e) { //小队申请
			var that = this;
			var agreestate = '';
			uni.showModal({
				title: that.lang.reviewrequest,
				content: that.lang.reviewrequestcontent,
				showCancel: true,
				cancelText: that.lang.disagree,
				confirmText: that.lang.agree,
				success: function(res) {
					if (res.confirm) {
						agreestate = 1
					} else if (res.cancel) {
						agreestate = 2
					}
					//训练者确认小队者查看
					var that = this;
					var data = {};
					data['state'] = agreestate;
					data['manage_id'] = e;
					commonBenefit.setUserManageApiMethod(data).then(res => {
						if (res) {
							Base.publicshowtoastsuccess(res.msg, commonBenefit.automaticurl('user'))
						}
					});
				}
			});
		},
		//跳转客服
		// khurl() { 
		// 	var that = this;
		// 	 uni.reLaunch({
		// 	 	url:"https://work.weixin.qq.com/kfid/kfc6187a4093b69fdcf",
		// 	 })
		// },
		apply() { //小队申请
			var that = this;
			commonBenefit.getUserManageApiMethod().then(res => {
				that.applaymanage = res;
			});
		}
	}
}